/*
============================================================================
 Name		: variasVentanasContainer.cpp
 Author	  : Ignacio Lopez
 Copyright   : GPL
 Description : Container control implementation
============================================================================
*/

// INCLUDE FILES
#include "FindMe2ndContainerGps.h"

#include <eiklabel.h>  // for example label control


_LIT(KGpsStatus, "GPS status: ");
_LIT(KLatitude, "Latitude: ");
_LIT(KLongitude, "Longitude: ");
_LIT(KNumSat, "Num. satellites: ");
_LIT(KAltitude, "Altitude(m): ");
_LIT(KFix, "GPS Fix: ");

// ================= MEMBER FUNCTIONS =======================

// ---------------------------------------------------------
// CFindMe2ndContainerGps::ConstructL(const TRect& aRect)
// EPOC two phased constructor
// ---------------------------------------------------------
//
void CFindMe2ndContainerGps::ConstructL(const TRect& aRect)
	{
	CreateWindowL();

	iLabelStatus = new (ELeave) CEikLabel;
	iLabelStatus->SetContainerWindowL( *this );	
	iLabelStatus->SetTextL(_L("GPS status: Idle"));

	iLabelLatitude = new (ELeave) CEikLabel;
	iLabelLatitude->SetContainerWindowL( *this );
	iLabelLatitude->SetTextL(KLatitude);
	
	iLabelLongitude = new (ELeave) CEikLabel;
	iLabelLongitude->SetContainerWindowL( *this );
	iLabelLongitude->SetTextL(KLongitude);
	
	iLabelGpsSignal = new (ELeave) CEikLabel;
	iLabelGpsSignal->SetContainerWindowL( *this );
	iLabelGpsSignal->SetTextL(_L("GPS Fix : No"));
	
	iLabelNumSat = new (ELeave) CEikLabel;
	iLabelNumSat->SetContainerWindowL( *this );
	iLabelNumSat->SetTextL(KNumSat);
	
	iLabelAlt = new (ELeave) CEikLabel;
	iLabelAlt->SetContainerWindowL( *this );
	iLabelAlt->SetTextL(KAltitude);

	SetRect(aRect);
	ActivateL();
	}

// Destructor
CFindMe2ndContainerGps::~CFindMe2ndContainerGps()
	{
	delete iLabelStatus;
	delete iLabelLatitude;
	delete iLabelLongitude;
	delete iLabelGpsSignal;
	delete iLabelNumSat;
	delete iLabelAlt;
	}

// ---------------------------------------------------------
// CFindMe2ndContainerGps::SizeChanged()
// Called by framework when the view size is changed
// ---------------------------------------------------------
//
void CFindMe2ndContainerGps::SizeChanged()
	{
	// TODO: Add here control resize code etc.
	iLabelStatus->SetExtent( TPoint(5,5), iLabelStatus->MinimumSize() );
	iLabelLatitude->SetExtent( TPoint(5,25), iLabelLatitude->MinimumSize() );
	iLabelLongitude->SetExtent( TPoint(5,45), iLabelLongitude->MinimumSize());
	iLabelNumSat->SetExtent( TPoint(5,65), iLabelNumSat->MinimumSize());
	iLabelAlt->SetExtent( TPoint(5,85), iLabelAlt->MinimumSize());
	iLabelGpsSignal->SetExtent( TPoint(5,105), iLabelGpsSignal->MinimumSize());
	}

// ---------------------------------------------------------
// CFindMe2ndContainerGps::CountComponentControls() const
// ---------------------------------------------------------
//
TInt CFindMe2ndContainerGps::CountComponentControls() const
	{
	return 6; // return nbr of controls inside this container
	}

// ---------------------------------------------------------
// CFindMe2ndContainerGps::ComponentControl(TInt aIndex) const
// ---------------------------------------------------------
//
CCoeControl* CFindMe2ndContainerGps::ComponentControl(TInt aIndex) const
	{
	switch ( aIndex )
		{
		case 0:
			return iLabelStatus;
		case 1:
			return iLabelLatitude;
		case 2:
			return iLabelLongitude;
		case 3:
			return iLabelGpsSignal;
		case 4:
			return iLabelNumSat;
		case 5:
			return iLabelAlt;
		default:
			return NULL;
		}
	}

// ---------------------------------------------------------
// CFindMe2ndContainerGps::Draw(const TRect& aRect) const
// ---------------------------------------------------------
//
void CFindMe2ndContainerGps::Draw(const TRect& aRect) const
	{
	CWindowGc& gc = SystemGc();
	// TODO: Add your drawing code here
	// example code...
	gc.SetPenStyle( CGraphicsContext::ENullPen );
	gc.SetBrushColor( KRgbWhite );
	gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
	gc.DrawRect( aRect );
	}

// ---------------------------------------------------------
// CFindMe2ndContainerGps::HandleControlEventL(
//	 CCoeControl* aControl,TCoeEvent aEventType)
// ---------------------------------------------------------
//
void CFindMe2ndContainerGps::HandleControlEventL(
	CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
	{
	// TODO: Add your control event handler code here
	}

void CFindMe2ndContainerGps::DisplayLabel(const enum TDisplaySection& aSection, const TDesC& aText) 
	{
		TBuf<MAXLENTEXTODISPLAY> message;
		if (aText.Length() > MAXLENTEXTODISPLAY)
			message.Copy(aText.Left(MAXLENTEXTODISPLAY));	
		else
			message.Copy(aText);
		
		TBuf<64> text; /* I think is enough */
		switch (aSection)
		{		
			case EGpsStatus:
				text.Copy(KGpsStatus);
				text.Append(message);
				iLabelStatus->SetTextL(text);
				break;
			case ELatitude:
				text.Copy(KLatitude);
				text.Append(message.Left(8));
				iLabelLatitude->SetTextL(text);
				break;
			case ELongitude:
				text.Copy(KLongitude);
				text.Append(message.Left(8));
				iLabelLongitude->SetTextL(text);
				break;
			case ENumSat:
				text.Copy(KNumSat);
				text.Append(message);
				iLabelNumSat->SetTextL(text);
				break;
			case EAltitude:
				text.Copy(KAltitude);
				text.Append(message);
				iLabelAlt->SetTextL(text);
				break;
			case EGpsFix:
				text.Copy(KFix);
				text.Append(message);
				iLabelGpsSignal->SetTextL(text);
				break;
			default:
				break;
		}
		SizeChanged();
		DrawNow();
	}

